//
//  DKUnauthorizedMainBillCell.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/24.
//

#import "DKUnauthorizedMainBillCell.h"
#import "DKUnathorizedMainNoBillView.h"
#import "DKUnauthProductCell.h"
static NSString * DK_UnauthorizedMainBillCellId = @"DK_UnauthorizedMainBillCellId";

@interface DKUnauthorizedMainBillCell()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView * dk_UnauthorizeMainBillTableView;
@property (nonatomic, strong)DKUnathorizedMainNoBillView * dkUnathorizedMainNoBillView;
@end
@implementation DKUnauthorizedMainBillCell
+ (instancetype)unauthorizedMainBillCell:(UITableView *)tableView{
    DKUnauthorizedMainBillCell * dk_UnauthorizedMainBillCell = [tableView dequeueReusableCellWithIdentifier:DK_UnauthorizedMainBillCellId];
    if (!dk_UnauthorizedMainBillCell) {
        dk_UnauthorizedMainBillCell = [[DKUnauthorizedMainBillCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DK_UnauthorizedMainBillCellId];
    }
    dk_UnauthorizedMainBillCell.backgroundColor = [UIColor clearColor];
    dk_UnauthorizedMainBillCell.selectionStyle = UITableViewCellSelectionStyleNone;
    dk_UnauthorizedMainBillCell.accessoryType = UITableViewCellAccessoryNone;
    return dk_UnauthorizedMainBillCell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UIView *UnauthorizedMainBillView = [[UIView alloc] init];
    UnauthorizedMainBillView.backgroundColor = UIColor.whiteColor;
    UnauthorizedMainBillView.layer.cornerRadius = DK_IsWidthScale(20);
    UnauthorizedMainBillView.clipsToBounds = YES;
    [self.contentView addSubview:UnauthorizedMainBillView];
    [UnauthorizedMainBillView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(-DK_IsWidthScale(13)));
    }];
    
    UILabel * dk_billLab = [[UILabel alloc] init];
    dk_billLab.textColor = DK_Hex(@"#333333");
    dk_billLab.font = DK_FONT_Medium(15);
    dk_billLab.text = @"My bills";
    [UnauthorizedMainBillView addSubview:dk_billLab];
    [dk_billLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(20)));
        make.top.equalTo(@(DK_IsWidthScale(22)));
        make.height.equalTo(@(DK_IsWidthScale(21)));
    }];
    self.dkUnathorizedMainNoBillView = [[DKUnathorizedMainNoBillView alloc] init];
    [UnauthorizedMainBillView addSubview:self.dkUnathorizedMainNoBillView];
    [self.dkUnathorizedMainNoBillView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(dk_billLab).offset(DK_IsWidthScale(12));
        make.height.equalTo(@(DK_IsWidthScale(88)));
    }];
    
    self.dk_UnauthorizeMainBillTableView = [[UITableView alloc] init];
    self.dk_UnauthorizeMainBillTableView.backgroundColor = UIColor.clearColor;
    self.dk_UnauthorizeMainBillTableView.delegate = self;
    self.dk_UnauthorizeMainBillTableView.dataSource = self;
    self.dk_UnauthorizeMainBillTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.dk_UnauthorizeMainBillTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.dk_UnauthorizeMainBillTableView.showsVerticalScrollIndicator = NO;
    [UnauthorizedMainBillView addSubview:self.dk_UnauthorizeMainBillTableView];
    [self.dk_UnauthorizeMainBillTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(dk_billLab.mas_bottom).offset(DK_IsWidthScale(7.5));
        make.bottom.equalTo(@(-DK_IsWidthScale(13.5)));
    }];
}
-(void)setOrderRecordList:(NSArray *)orderRecordList{
    _orderRecordList = orderRecordList;
    if(_orderRecordList.count){
        self.dkUnathorizedMainNoBillView.hidden = YES;
        self.dk_UnauthorizeMainBillTableView.hidden = NO;
        [self.dk_UnauthorizeMainBillTableView reloadData];
    }else{
        self.dkUnathorizedMainNoBillView.hidden = NO;
        self.dk_UnauthorizeMainBillTableView.hidden = YES;
    }
}
#pragma mark -- UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _orderRecordList.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DK_IsWidthScale(43);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DKUnauthProductCell *unauthProductCell = [DKUnauthProductCell unauthProductCell:tableView];
    unauthProductCell.orderRecordListMdl = _orderRecordList[indexPath.row];
    return unauthProductCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DKOrderRecordListModel * orderRecordListMdl = _orderRecordList[indexPath.row];
    if(self.BillRecordBlock){
        self.BillRecordBlock(orderRecordListMdl);
    }
}
@end
